package faac.http.MainPage;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import faac.Manager;

/**
 *
 * @author -D@@G-
 */
public class user_group_props_add extends MainPageServletActions{
    @Override
public String perform(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String ns = request.getParameter("ns"); // Имя сервиса
        if (!Manager.getInstance().getServiceNames().contains(ns)) {
            return "/main?page=error&id=0&ret=index";
        }

String gr = request.getParameter("gr");

        if(gr.equals("")){
           return "/main?page=error&id=4&ret=index";
        }
        String[] s = Manager.getInstance().getService(ns).getProps().getStringProperty("auth.groups").split(";");
        for(int i=0;i<s.length;i++){
            if(s[i].equalsIgnoreCase(gr)){
 return "/main?page=error&id=5&ret=index";
        }
        Manager.getInstance().getService(ns).getProps().setStringProperty("auth.groups",
                Manager.getInstance().getService(ns).getProps().getStringProperty("auth.groups") + ";" + gr);
        Manager.getInstance().getService(ns).getProps().setStringProperty("auth.group_"+gr,"");
        Manager.getInstance().getService(ns).getProps().save();
        return "/main?page=message&id=0&ret=index";
    }

        return null;
    }
}
